package ooday03;

public class RefArrayDemo {
    public static void main(String[] args) {
        /*
        //声明Dog型数组dogs，包含三种元素，每个元素都是Dog类型，默认值为null
        Dog[] dogs=new Dog[3];
        //声明Chick型数组Chick，包含三种元素，每个元素都是Chick类型，默认值为null
        Chick[] chicks=new Chick[3];
        //声明Fish型数组Fish，包含三种元素，每个元素都是Fish类型，默认值为null
        Fish[] fish=new Fish[2];
         */

        /*
        Dog[] dogs = new Dog[3];
        dogs[0] = new Dog("小黑", 2, "黑");
        dogs[1] = new Dog("小黑", 2, "黑");
        dogs[2] = new Dog("小黑", 2, "黑");

        Chick[] chicks = new Chick[2];
        chicks[0] = new Chick("小白", 2, "白");
        chicks[1] = new Chick("小白", 2, "白");

        Fish[] fish = new Fish[4];
        fish[0] = new Fish("小金", 2, "金");
        fish[1] = new Fish("小金", 2, "金");
        fish[2] = new Fish("小金", 2, "金");
        fish[3] = new Fish("小金", 2, "金");
         */

        Dog[] dogs = new Dog[3];
        dogs[0] = new Dog("小黑", 2, "黑");
        dogs[1] = new Dog("小黑", 2, "黑");
        dogs[2] = new Dog("小黑", 2, "黑");
        System.out.println(dogs[0].name);
        dogs[1].age=4;
        dogs[2].swim();
        System.out.println("-------------");
        for (int i = 0;i< dogs.length;i++){
            System.out.println(dogs[i].name);
            dogs[i].eat();
        }

        Chick[] chicks=new Chick[2];
        chicks[0] = new Chick("小白", 2, "白");
        chicks[1] = new Chick("小白", 2, "白");
        for (int i = 0;i< chicks.length;i++){
            System.out.println(chicks[i].name);
            chicks[i].layEggs();
        }

        Fish[] fish = new Fish[4];
        fish[0] = new Fish("小金", 2, "金");
        fish[1] = new Fish("小金", 2, "金");
        fish[2] = new Fish("小金", 2, "金");
        fish[3] = new Fish("小金", 2, "金");
        for (int i = 0;i< fish.length;i++){
            System.out.println(fish[i].name);
            fish[i].swim();
        }

    }
}
